const nodemailer = require('nodemailer');

class Mail {
  constructor(user, password, to, subject, text, attachements) {
    this.transporter = nodemailer.createTransport({
      service: 'qq',
      auth: {
        user: user,
        pass: password
      }
    });

    this.mailOptions = {
      from: user,
      to: to,
      subject: subject,
      text: text,
      attachments: attachements
    };
  }

  send() {
    this.transporter.sendMail(this.mailOptions, function (err, info) {
      if (err) {
        console.log(err);
        return;
      }
      console.log('发送成功');
    });
  }
}

exports.Mail = Mail;